/*  $OpenBSD: stdio.h,v 1.35 2006/01/13 18:10:09 miod Exp $ */
/*  $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $   */

/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Chris Torek.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *  @(#)stdio.h 5.17 (Berkeley) 6/3/91
 */

/** @defgroup stdio Stdio
 * @ingroup libc
 */

#ifndef _STDIO_H_
#define _STDIO_H_

#include <sys/cdefs.h>
#include <sys/types.h>

#include <stdarg.h>
#include <stddef.h>

#define __need_NULL
#include <stddef.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */


typedef off_t fpos_t;
typedef off64_t fpos64_t;

struct __sFILE;
typedef struct __sFILE FILE;

extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
/* C99 and earlier plus current C++ standards say these must be macros. */
#define stdin stdin
#define stdout stdout
#define stderr stderr

/*
 * The following three definitions are for ANSI C, which took them
 * from System V, which brilliantly took internal interface macros and
 * made them official arguments to setvbuf(), without renaming them.
 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
 *
 * Although numbered as their counterparts above, the implementation
 * does not rely on this.
 */
#define _IOFBF  0       /* setvbuf should set fully buffered */
#define _IOLBF  1       /* setvbuf should set line buffered */
#define _IONBF  2       /* setvbuf should set unbuffered */

#ifdef __LITEOS__
#define BUFSIZ  (8 * 1024)      /* size of buffer used by setbuf */
#else
#define BUFSIZ  1024        /* size of buffer used by setbuf */
#endif
#define EOF (-1)

/*
 * FOPEN_MAX is a minimum maximum, and is the number of streams that
 * stdio can provide without attempting to allocate further resources
 * (which could fail).  Do not use this for anything.
 */

#define FOPEN_MAX   20  /* must be <= OPEN_MAX <sys/syslimits.h> */
#define FILENAME_MAX    1024    /* must be <= PATH_MAX <sys/syslimits.h> */

/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
#if __BSD_VISIBLE || __XPG_VISIBLE
#define P_tmpdir    "/tmp/"
#endif
#define L_tmpnam    1024    /* XXX must be == PATH_MAX */
#define TMP_MAX     308915776

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

/*
 * Functions defined in ANSI C standard.
 */

/**
* @ingroup stdio
*
* @par Description:
* The clearerr() function shall clear the end-of-file and error indicators for the stream to which stream points.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see None
* @since Huawei LiteOS V100R001C00
*/
void clearerr(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The fclose() function shall clear the end-of-file and error indicators for the stream to which stream points.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fclose() shall return 0, if it completes successfully;\n
*             otherwise, it shall return EOF.
*
* @par Errors
* <ul>
* <li><b>EBADF</b>: The file descriptor underlying stream is not valid.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fflush
* @since Huawei LiteOS V100R001C00
*/
int  fclose(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The feof() function shall test the end-of-file indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The feof() shall return non-zero if and only if the end-of-file indicator is set for stream.
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see clearerr | ferror | fopen
* @since Huawei LiteOS V100R001C00
*/
int  feof(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The ferror() function shall test the error indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The ferror() function shall return non-zero if and only if the error indicator is set for stream.
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see clearerr | feof | fopen
* @since Huawei LiteOS V100R001C00
*/
int  ferror(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* If stream points to an output stream or an update stream in which the most recent operation was not input, fflush()
* shall cause any unwritten data for that stream to be written to the file, [CX] [Option Start]  and the last data
* modification and last file status change timestamps of the underlying file shall be marked for update.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fflush() function shall return 0, if it completes successfully;\n
*              otherwise, it shall set the error indicator for the stream, return EOF and set errno to
*              indicate the error.
*
* @par Errors
* <ul>
* <li><b>EBADF</b>: The file descriptor underlying stream is not valid.</li>
* <li><b>ENOBUFS</b>: No buffer space available.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see sync | write | fclose | fopen
* @since Huawei LiteOS V100R001C00
*/
int  fflush(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* the fgetc() function shall obtain the next byte as an unsigned char converted to an int, from the input stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fgetc() shall return the next byte from the input stream pointed to by stream
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see feof | ferror | fgets | fread | fscanf | getchar | getc | gets
* @since Huawei LiteOS V100R001C00
*/
int  fgetc(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The fgets() function shall read bytes from stream into the array pointed to by s until n-1 bytes are read, or a <
* newline> is read and transferred to s, or an end-of-file condition is encountered.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #char* Upon successful completion, fgets() shall return s. If the stream is at end-of-file,
* the end-of-file indicator for the stream shall be set and fgets() shall return a null pointer.
* If a read error occurs, the error indicator for the stream shall be set,
* fgets() shall return a null pointer,  and shall set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: Invalid argument.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fgetc | fopen | fread | fscanf | getc
* @since Huawei LiteOS V100R001C00
*/
char    *fgets(char * __restrict s, int n, FILE * __restrict f);

/**
* @ingroup stdio
*
* @par Description:
* The fprintf() function shall place output on the named output stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fprintf() functions shall return the number of bytes transmitted.
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fputc | fscanf
* @since Huawei LiteOS V100R001C00
*/
int  fprintf(FILE * __restrict , const char * __restrict, ...)
        __printflike(2, 3);

/**
* @ingroup stdio
*
* @par Description:
* The fputc() function shall write the byte (converted to an unsigned char) to the output stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fputc() shall return the value it has written. Otherwise, it shall return EOF.
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fprintf | fscanf | fputs
* @since Huawei LiteOS V100R001C00
*/
int  fputc(int, FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The fputs() function shall  writes the string s to stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fputs() shall return the 0, if it completes successfully;\n
*              Otherwise, it shall return EOF.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fputc | puts
* @since Huawei LiteOS V100R001C00
*/
int  fputs(const char * __restrict, FILE * __restrict);

/**
* @ingroup stdio
*
* @par Description:
* The fread() function shall read into the array pointed to by ptr up to nitems elements whose size is specified by
* size in bytes, from the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #size_t Upon successful completion, fread() shall return the number of elements successfully read
*                 which is less than nitems only if a read error or end-of-file is encountered. \n
*                 If size or nitems is 0, fread() shall return 0 and the contents of the array
*                 and the state of the stream remain unchanged.\n
*                 Otherwise, if a read error occurs, the error indicator for the stream shall be set,
*                 and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EEOF</b>: The end of file has been reached</li>
* <li><b>EBADF</b>: Bad file number.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see read | write | feof
* @since Huawei LiteOS V100R001C00
*/
size_t   fread(void * __restrict ptr, size_t size, size_t nitems, FILE * __restrict stream);

/**
* @ingroup stdio
*
* @par Description:
*  The fscanf() function scans shall read from the named input stream
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
*              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
*              The  value  EOF is returned if the end of input is reached
*              before either the first successful conversion or a matching failure  occurs.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fprintf | getc | scanf
* @since Huawei LiteOS V100R001C00
*/
int  fscanf(FILE * __restrict, const char * __restrict, ...)
        __scanflike(2, 3);

/**
* @ingroup stdio
*
* @par Description:
* The fwrite() function shall write, from the array pointed to by ptr, up to nitems elements whose size is specified by
* size, to the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #size_t The fwrite() function shall return the number of elements successfully written,
*                 which may be less than nitems if a write error is encountered.
*                 If size or nitems is 0, fwrite() shall return 0 and the state of the stream remains unchanged.
*                 Otherwise, if a write error occurs, the error indicator for the stream shall be set,
*                 and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: Invalid argument.</li>
* <li><b>EBADF</b>: Bad file number.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see puts | fwrite | ferror | fopen
* @since Huawei LiteOS V100R001C00
*/
size_t   fwrite(const void * __restrict ptr, size_t size, size_t nitems, FILE * __restrict stream);

/**
* @ingroup stdio
*
* @par Description:
* The getc() function shell get a byte from a stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The getc() function return the character read as an unsigned char
*              cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see putc | getchar
* @since Huawei LiteOS V100R001C00
*/
int  getc(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The getchar() function shell get a byte from a stdin stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The getchar() function return the character read as an unsigned char
*              cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see putchar | getc
* @since Huawei LiteOS V100R001C00
*/
int  getchar(void);
ssize_t  getdelim(char ** __restrict, size_t * __restrict, int,
        FILE * __restrict);
ssize_t  getline(char ** __restrict, size_t * __restrict, FILE * __restrict);

/**
* @ingroup stdio
*
* @par Description:
* The perror() function shell write error messages to standard error.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fprintf | fputc
* @since Huawei LiteOS V100R001C00
*/
void     perror(const char *);

/**
* @ingroup stdio
*
* @par Description:
* The printf() function shall place output on the stdout stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The printf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see snprintf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  printf(const char * __restrict, ...)
        __printflike(1, 2);

/**
* @ingroup stdio
*
* @par Description:
* The putc() function shell put a byte from a stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The putc() function return the character written as an unsigned char
*              cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see putchar | getc
* @since Huawei LiteOS V100R001C00
*/
int  putc(int, FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The putchar() function shell put a byte from a stdin stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The putchar() function return the character written as an unsigned char
*              cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see getchar | putc
* @since Huawei LiteOS V100R001C00
*/
int  putchar(int);

/**
* @ingroup stdio
*
* @par Description:
* The puts() function shell put a string on standard output.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int Upon successful completion, puts() shall return 0. Otherwise, it shall return EOF, shall set an
*              error indicator for the stream, and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EBADF</b>: Bad file number.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fputs | putc
* @since Huawei LiteOS V100R001C00
*/
int  puts(const char *);

/**
* @ingroup stdio
*
* @par Description:
* The remove() function shell remove a file or directory.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The remove() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see unlink | rmdir
* @since Huawei LiteOS V100R001C00
*/
int  remove(const char *);

/**
* @ingroup stdio
*
* @par Description:
* The rewind() function sets the file position indicator for the stream pointed to by stream
* to the beginning of the file.  It is equivalent to:\n
*              (void) fseek(stream, 0L, SEEK_SET)
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseek | fseeko
* @since Huawei LiteOS V100R001C00
*/
void     rewind(FILE *);

/**
* @ingroup stdio
*
* @par Description:
*  The scanf() function scans shall read from the stdin stream
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
*              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
*              The  value  EOF is returned if the end of input is reached
*              before either the first successful conversion or a matching failure  occurs.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fprintf | getc | scanf
* @since Huawei LiteOS V100R001C00
*/
int  scanf(const char * __restrict, ...)
        __scanflike(1, 2);

/**
* @ingroup stdio
*
* @par Description:
* The setvbuf() function assign buffering to a stream, and is exactly equivalent to the call\n
*           setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: Invalid argument.</li>
* <li><b>ENOBUFS</b>: No buffer space available.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see setvbuf | fopen
* @since Huawei LiteOS V100R001C00
*/
void     setbuf(FILE * __restrict, char * __restrict);

/**
* @ingroup stdio
*
* @par Description:
* The setvbuf() function may be used after the stream pointed to by stream
* is associated with an open file but before any other operation
* (other than an unsuccessful call to setvbuf()) is performed on the stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int Upon successful completion, setvbuf() shall return 0.\n
*              Otherwise, it shall return EOF if an invalid value
*              is given for type or if the request cannot be honored,
*              and may set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: Invalid argument.</li>
* <li><b>ENOBUFS</b>: No buffer space available.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see setbuf | fopen
* @since Huawei LiteOS V100R001C00
*/
int  setvbuf(FILE * __restrict, char * __restrict, int, size_t);

/**
* @ingroup stdio
*
* @par Description:
*  The scanf() function scans shall read from the named string.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
*              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
*              The  value  EOF is returned if the end of input is reached
*              before either the first successful conversion or a matching failure  occurs.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fprintf | getc | scanf
* @since Huawei LiteOS V100R001C00
*/
int  sscanf(const char * __restrict, const char * __restrict, ...)
        __scanflike(2, 3);

/**
* @ingroup stdio
*
* @par Description:
*  The ungetc() function shall push the byte specified by c (converted to an unsigned char)
*  back onto the input stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int Upon successful completion, ungetc() shall return the byte pushed back after conversion.\n
*              Otherwise, it shall return EOF.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseek | getc | fsetpos
* @since Huawei LiteOS V100R001C00
*/
int  ungetc(int c, FILE * stream);

/**
* @ingroup stdio
*
* @par Description:
* The vfprintf() function shall format output of a stdarg argument list to the named file descriptor.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The vfprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  vfprintf(FILE * __restrict, const char * __restrict, __va_list)
        __printflike(2, 0);

/**
* @ingroup stdio
*
* @par Description:
* The vprintf() function shall format output of a stdarg argument list to the stdout.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The vprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  vprintf(const char * __restrict, __va_list)
        __printflike(1, 0);

#ifdef __LITEOS__
/**
* @ingroup stdio
*
* @par Description:
* The dprintf() function shall place output on the stdout.
*
* @attention
* <ul>
* <li>LiteOS shall place output on the stdout instead of a named file descriptor.</li>
* </ul>
*
* @retval #int The dprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | vdprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
void dprintf(const char * __restrict, ...);
#else
int dprintf(int, const char * __restrict, ...) __printflike(2, 3);
#endif

int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0);

/**
* @ingroup stdio
*
* @par Description:
* The gets() function shall get a string from a stdin stream.
*
* @attention
* <ul>
* <li>gets is unsafe, use fgets instead.</li>
* </ul>
*
* @retval #char* Upon successful completion, gets() shall return s; otherwise, it shall return NULL;
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef __AUDIT__
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
char* gets(char* s) __attribute__((deprecated("gets is unsafe, use fgets instead")));
#endif

/**
* @ingroup stdio
*
* @par Description:
* The sprintf() function shall write to the string according to the format.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The sprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int sprintf(char* __restrict, const char* __restrict, ...)
    __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");

/**
* @ingroup stdio
*
* @par Description:
* The vsprintf() function shall format output of a stdarg argument list to the string.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The vsprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int vsprintf(char* __restrict, const char* __restrict, __va_list)
#ifdef __LITEOS__
    ;
#else
    __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
#endif

/**
* @ingroup stdio
*
* @par Description:
* The tmpnam() function shall generate a string that is a valid pathname that does not name an existing file.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #char* Upon successful completion, tmpnam() shall return a pointer to a string. If no suitable string can be generated, the
*                tmpnam() function shall return a null pointer.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | mkstemp
* @since Huawei LiteOS V100R001C00
*/
char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead")));
#if __XPG_VISIBLE
char* tempnam(const char*, const char*)
    __attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead")));
#endif
#endif

/**
* @ingroup stdio
*
* @par Description:
* The rename() function shall change the name of a file.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int Upon successful completion, the rename() function shall return 0.\n
*              Otherwise, it shall return -1 and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: Invalid argument.</li>
* <li><b>ENOENT</b>: No such file or directory./li>
* <li><b>EXDEV</b>: Cross-device link.</li>
* <li><b>ENOSYS</b>: Rename function not implemented.</li>
* <li><b>EBUSY</b>: Device or resource busy.</li>
* <li><b>EEXIST</b>: File exists.</li>
* <li><b>ENXIO</b>: No such device or address.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see rmdir | unlink
* @since Huawei LiteOS V100R001C00
*/
int rename(const char*, const char*);
int renameat(int, const char*, int, const char*);

/**
* @ingroup stdio
*
* @par Description:
* The fseek() function shall set the file-position indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fseek() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
* <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fgetpos | fseeko
* @since Huawei LiteOS V100R001C00
*/
int fseek(FILE*, long, int);

/**
* @ingroup stdio
*
* @par Description:
* The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #long The ftell() function shall return the current offset, if it completes successfully;\n
*               otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseek | ftello
* @since Huawei LiteOS V100R001C00
*/
long ftell(FILE*);

#if defined(__USE_FILE_OFFSET64)
int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64);
int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64);
int fseeko(FILE*, off_t, int) __RENAME(fseeko64);
off_t ftello(FILE*) __RENAME(ftello64);
#  if defined(__USE_BSD)
FILE* funopen(const void*,
              int (*)(void*, char*, int),
              int (*)(void*, const char*, int),
              fpos_t (*)(void*, fpos_t, int),
              int (*)(void*)) __RENAME(funopen64);
#  endif
#else
/**
* @ingroup stdio
*
* @par Description:
* The fgetpos() function shall store the current values of the parse state (if any) and file position indicator for the
* stream pointed to by stream in the object pointed to by pos.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fgetpos() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return 1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fsetpos
* @since Huawei LiteOS V100R001C00
*/
int fgetpos(FILE*, fpos_t*);

/**
* @ingroup stdio
*
* @par Description:
* The fsetpos() function shall set the file position and state indicators for the stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fsetpos() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
* <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseeko | fgetpos
* @since Huawei LiteOS V100R001C00
*/
int fsetpos(FILE*, const fpos_t*);

/**
* @ingroup stdio
*
* @par Description:
* The fseeko() function shall set the file-position indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fseeko() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
* <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fgetpos | fseek
* @since Huawei LiteOS V100R001C00
*/
int fseeko(FILE*, off_t, int);

/**
* @ingroup stdio
*
* @par Description:
* The ftello() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #off_t The ftello() function shall return the current offset, if it completes successfully;\n
*                otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseeko | ftell
* @since Huawei LiteOS V100R001C00
*/
off_t ftello(FILE*);
#  if defined(__USE_BSD)
FILE* funopen(const void*,
              int (*)(void*, char*, int),
              int (*)(void*, const char*, int),
              fpos_t (*)(void*, fpos_t, int),
              int (*)(void*));
#  endif
#endif
int fgetpos64(FILE*, fpos64_t*);
int fsetpos64(FILE*, const fpos64_t*);

/**
* @ingroup stdio
*
* @par Description:
* The fseeko64() function shall set the file-position indicator for the stream pointed to by stream for the 64-bit OS.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fseeko64() function shall return 0, if it completes successfully;\n
*              otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* <li><b>EINVAL</b>: The whence argument to fseek() was not SEEK_SET, SEEK_END, or SEEK_CUR.</li>
* <li><b>EBADF</b>: The stream specified is not a seekable stream.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fopen | fgetpos
* @since Huawei LiteOS V100R001C00
*/
int fseeko64(FILE*, off64_t, int);

/**
* @ingroup stdio
*
* @par Description:
* The ftello64() function shall obtain the current value of the file-position indicator
* for the stream pointed to by stream for the 64-bit OS.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #off64_t The ftello64() function shall return the current offset, if it completes successfully;\n
*                  otherwise, it shall return -1 and set errno to indicate the error.
*
* @par Errors
* <ul>
* <li><b>ESPIPE</b>: Illegal seek.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fseeko64
* @since Huawei LiteOS V100R001C00
*/
off64_t ftello64(FILE*);
#if defined(__USE_BSD)
FILE* funopen64(const void*,
                int (*)(void*, char*, int),
                int (*)(void*, const char*, int),
                fpos64_t (*)(void*, fpos64_t, int),
                int (*)(void*));
#endif

/**
* @ingroup stdio
*
* @par Description:
* The fopen() function shall open the file whose pathname is the string pointed to by pathname, and associates a stream
* with it.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #FILE* Upon successful completion, fopen() shall return a pointer to the object controlling the stream.\n
*                Otherwise, a null pointer shall be returned, and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: The mode argument is not a valid mode.</li>
* <li><b>EMFILE</b>: The file descriptor is greater than SHRT_MAX</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see open | fdopen | fclose
* @since Huawei LiteOS V100R001C00
*/
FILE* fopen(const char* __restrict, const char* __restrict);

/**
* @ingroup stdio
*
* @par Description:
* The fopen64() function shall open the file whose pathname is the string pointed to by pathname, and associates a stream
* with it.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #FILE* Upon successful completion, fopen64() shall return a pointer to the object controlling the stream.\n
*                Otherwise, a null pointer shall be returned, and errno shall be set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EINVAL</b>: The mode argument is not a valid mode.</li>
* <li><b>EMFILE</b>: The file descriptor is greater than SHRT_MAX</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see open | fdopen | fclose
* @since Huawei LiteOS V100R001C00
*/
FILE* fopen64(const char* __restrict, const char* __restrict);

/**
* @ingroup stdio
*
* @par Description:
* The freopen() function opens the file whose name is the string pointed to by path and associates the stream pointed
* to by stream with it.  The original stream (if it exists) is  closed.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #FILE* The freopen() function shall return a pointer to a stream, if it completes successfully;\n
*                otherwise, a null pointer shall be returned and errno set to indicate the error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see open | fopen | fclose
* @since Huawei LiteOS V100R001C00
*/
FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict);
FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict);
FILE* tmpfile(void);
FILE* tmpfile64(void);

#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE

/**
* @ingroup stdio
*
* @par Description:
* The snprintf() function shall write at most size bytes to the string.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The snprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  snprintf(char * __restrict, size_t, const char * __restrict, ...)
        __printflike(3, 4);

/**
* @ingroup stdio
*
* @par Description:
*  The vfscanf() function scans a variable argument list from the named input stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int On success, these functions return the number of input items successfully matched and assigned;\n
*              this can be fewer than provided for, or even zero, in the event of an early matching failure.\n
*              The  value  EOF is returned if the end of input is reached
*              before either the first successful conversion or a matching failure  occurs.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see vscanf | getc | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  vfscanf(FILE * __restrict, const char * __restrict, __va_list)
        __scanflike(2, 0);

/**
* @ingroup stdio
*
* @par Description:
*  The vscanf() function scans a variable argument list from the standard input.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int On success, the vscanf() function return the number of input items successfully matched and assigned;\n
* this can be fewer than provided for, or even zero, in the event of an early matching failure.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see vfscanf | getc | fprintf
* @since Huawei LiteOS V100R001C00
*/

int  vscanf(const char *, __va_list)
        __scanflike(1, 0);

/**
* @ingroup stdio
*
* @par Description:
* The vsnprintf() function shall format output of a stdarg argument list to the string at most size bytes.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The vsnprintf() function shall return the number of characters printed.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see printf | dprintf | fprintf
* @since Huawei LiteOS V100R001C00
*/
int  vsnprintf(char * __restrict, size_t, const char * __restrict, __va_list)
        __printflike(3, 0);

int  vsscanf(const char * __restrict, const char * __restrict, __va_list)
        __scanflike(2, 0);
#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */

/*
 * Functions defined in POSIX 1003.1.
 */
#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
#define L_ctermid   1024    /* size for ctermid(); PATH_MAX */

/**
* @ingroup stdio
*
* @par Description:
* The fdopen() function shall associate a stream with a file descriptor.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #FILE* The fdopen() function shall return a pointer to a stream, if it completes successfully;\n
*                otherwise, a null pointer shall be returned and errno set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EMFILE</b>: The file descriptor is greater than SHRT_MAX</li>
* <li><b>EINVAL</b>: The mode argument is not a valid mode.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fclose | fopen | open
* @since Huawei LiteOS V100R001C00
*/
FILE    *fdopen(int, const char *);

/**
* @ingroup stdio
*
* @par Description:
* The fileno() function shall return the integer file descriptor associated with the stream.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The fileno() function return the integer value of the file descriptor associated with stream.\n
*              Otherwise, the value -1 shall be returned and errno set to indicate the error.
*
* @par Errors
* <ul>
* <li><b>EBADF</b>: The stream is not associated with a file.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see fdopen | fopen
* @since Huawei LiteOS V100R001C00
*/
int  fileno(FILE *);

#if (__POSIX_VISIBLE >= 199209)
int  pclose(FILE *);
FILE    *popen(const char *, const char *);
#endif

#if __POSIX_VISIBLE >= 199506

/**
* @ingroup stdio
*
* @par Description:
* The flockfile() function shall acquire for a thread ownership of a (FILE *) object.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see ftrylockfile | funlockfile
* @since Huawei LiteOS V100R001C00
*/
void     flockfile(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The ftrylockfile() function shall acquire for a thread ownership of a (FILE *) object if the object is available;
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The ftrylockfile() function shall return zero for success and non-zero to indicate that the lock cannot be acquired.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see flockfile | funlockfile
* @since Huawei LiteOS V100R001C00
*/
int  ftrylockfile(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The funlockfile() function shall relinquish the ownership granted to the thread.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #void None.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see flockfile | ftrylockfile
* @since Huawei LiteOS V100R001C00
*/
void     funlockfile(FILE *);

/*
 * These are normally used through macros as defined below, but POSIX
 * requires functions as well.
 */

/**
* @ingroup stdio
*
* @par Description:
* The getc_unlocked() function shell get a byte from a stream without the thread-safe.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The getc_unlocked() function return the character read as an unsigned char cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see putc_unlocked | getc
* @since Huawei LiteOS V100R001C00
*/
int  getc_unlocked(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The getchar_unlocked() function shell get a byte from a stdin stream without the thread-safe.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The getchar_unlocked() function return the character read as an unsigned char cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see putchar_unlocked | getchar
* @since Huawei LiteOS V100R001C00
*/
int  getchar_unlocked(void);

/**
* @ingroup stdio
*
* @par Description:
* The putc_unlocked() function shell put a byte from a stream without the thread-safe.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The putc_unlocked() function return the character written as an unsigned char cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see getc_unlocked | putc
* @since Huawei LiteOS V100R001C00
*/
int  putc_unlocked(int, FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The putchar_unlocked() function shell put a byte from a stdin stream without the thread-safe.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The putchar_unlocked() function return the character written as an unsigned char cast to an int or EOF on end of file or error.
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see getchar_unlocked | putchar
* @since Huawei LiteOS V100R001C00
*/
int  putchar_unlocked(int);
#endif /* __POSIX_VISIBLE >= 199506 */

#if __POSIX_VISIBLE >= 200809
FILE* fmemopen(void*, size_t, const char*);
FILE* open_memstream(char**, size_t*);
#endif /* __POSIX_VISIBLE >= 200809 */

#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */

/*
 * Routines that are purely local.
 */
#if __BSD_VISIBLE

/**
* @ingroup stdio
*
* @par Description:
* The asprintf() function shell allocate a string large enough to hold the output.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int  The asprintf() function return the number of bytes printed, if it completes successfully;\n
*               otherwise, it shall return -1.
*
* @par Errors
* <ul>
* <li><b>ENOMEM</b>: Insufficient storage space is available.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see malloc | free | printf
* @since Huawei LiteOS V100R001C00
*/
int  asprintf(char ** __restrict, const char * __restrict, ...)
        __printflike(2, 3);
char    *fgetln(FILE * __restrict, size_t * __restrict);
int  fpurge(FILE *);
void     setbuffer(FILE *, char *, int);
int  setlinebuf(FILE *);

/**
* @ingroup stdio
*
* @par Description:
* The vasprintf() function shell allocate a string large enough to hold the output.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int  The vasprintf() function return the number of bytes printed, if it completes successfully;\n
*               otherwise, it shall return -1.
*
* @par Errors
* <ul>
* <li><b>ENOMEM</b>: Insufficient storage space is available.</li>
* </ul>
*
* @par Dependency:
* <ul><li>stdio.h</li></ul>
* @see malloc | free | printf
* @since Huawei LiteOS V100R001C00
*/
int  vasprintf(char ** __restrict, const char * __restrict,
    __va_list)
        __printflike(2, 0);

void clearerr_unlocked(FILE*);
int feof_unlocked(FILE*);
int ferror_unlocked(FILE*);
int fileno_unlocked(FILE*);

#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
#endif /* __BSD_VISIBLE */

extern char* __fgets_chk(char*, int, FILE*, size_t);
extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
__errordecl(__fgets_too_small_error, "fgets called with size less than zero");

extern size_t __fread_chk(void * __restrict, size_t, size_t, FILE * __restrict, size_t);
extern size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread);
__errordecl(__fread_too_big_error, "fread called with size * count bigger than buffer");
__errordecl(__fread_overflow, "fread called with overflowing size * count");

extern size_t __fwrite_chk(const void * __restrict, size_t, size_t, FILE * __restrict, size_t);
extern size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite);
__errordecl(__fwrite_too_big_error, "fwrite called with size * count bigger than buffer");
__errordecl(__fwrite_overflow, "fwrite called with overflowing size * count");

#if defined(__BIONIC_FORTIFY)

__BIONIC_FORTIFY_INLINE
__printflike(3, 0)
int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
{
    return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
}

__BIONIC_FORTIFY_INLINE
__printflike(2, 0)
int vsprintf(char *dest, const char *format, __va_list ap)
{
    return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
}

#if defined(__clang__)
  #if !defined(snprintf)
    #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
    #define snprintf(...) __wrap_snprintf(__VA_ARGS__)
  #endif
#else
__BIONIC_FORTIFY_INLINE
__printflike(3, 4)
int snprintf(char *dest, size_t size, const char *format, ...)
{
    return __builtin___snprintf_chk(dest, size, 0,
        __bos(dest), format, __builtin_va_arg_pack());
}
#endif

#if defined(__clang__)
  #if !defined(sprintf)
    #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
    #define sprintf(...) __wrap_sprintf(__VA_ARGS__)
  #endif
#else
__BIONIC_FORTIFY_INLINE
__printflike(2, 3)
int sprintf(char *dest, const char *format, ...)
{
    return __builtin___sprintf_chk(dest, 0,
        __bos(dest), format, __builtin_va_arg_pack());
}
#endif

__BIONIC_FORTIFY_INLINE
size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) {
    size_t bos = __bos0(buf);

#if !defined(__clang__)
    if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
        return __fread_real(buf, size, count, stream);
    }

    if (__builtin_constant_p(size) && __builtin_constant_p(count)) {
        size_t total;
        if (__size_mul_overflow(size, count, &total)) {
            __fread_overflow();
        }

        if (total > bos) {
            __fread_too_big_error();
        }

        return __fread_real(buf, size, count, stream);
    }
#endif

    return __fread_chk(buf, size, count, stream, bos);
}

__BIONIC_FORTIFY_INLINE
size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) {
    size_t bos = __bos0(buf);

#if !defined(__clang__)
    if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
        return __fwrite_real(buf, size, count, stream);
    }

    if (__builtin_constant_p(size) && __builtin_constant_p(count)) {
        size_t total;
        if (__size_mul_overflow(size, count, &total)) {
            __fwrite_overflow();
        }

        if (total > bos) {
            __fwrite_too_big_error();
        }

        return __fwrite_real(buf, size, count, stream);
    }
#endif

    return __fwrite_chk(buf, size, count, stream, bos);
}

#if !defined(__clang__)

__BIONIC_FORTIFY_INLINE
char *fgets(char* dest, int size, FILE* stream) {
    size_t bos = __bos(dest);

    // Compiler can prove, at compile time, that the passed in size
    // is always negative. Force a compiler error.
    if (__builtin_constant_p(size) && (size < 0)) {
        __fgets_too_small_error();
    }

    // Compiler doesn't know destination size. Don't call __fgets_chk
    if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
        return __fgets_real(dest, size, stream);
    }

    // Compiler can prove, at compile time, that the passed in size
    // is always <= the actual object size. Don't call __fgets_chk
    if (__builtin_constant_p(size) && (size <= (int) bos)) {
        return __fgets_real(dest, size, stream);
    }

    // Compiler can prove, at compile time, that the passed in size
    // is always > the actual object size. Force a compiler error.
    if (__builtin_constant_p(size) && (size > (int) bos)) {
        __fgets_too_big_error();
    }

    return __fgets_chk(dest, size, stream, bos);
}

#endif /* !defined(__clang__) */

#endif /* defined(__BIONIC_FORTIFY) */


#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif /* _STDIO_H_ */
